/*
 * OpenSCAD File with the code to draw a part of the quadcopter in 3D
 * Part Number: 06
 * Version: 0.01
 * Units: mm
 * Last Modification: Sun Jun 27 23:41:03 WEST 2010
 *
 * Copyright (C) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

frominclude = 0;

p6_sizewidth = 31;

module p6_pipesin()
{
	for (pos = [[12, 12, (4.5/2)-1.5],[-12, 12, (4.5/2)-1.5],
				[12, -12, (4.5/2)-1.5],[-12, -12, (4.5/2)-1.5]]) {
		translate(v = pos) {
			cylinder(h=4.5, r=1.5, center=true, $fn=60);
		}
	}
}

module p6_pipesout()
{
	for (pos = [[12, 12, (4/2)-1],[-12, 12, (4/2)-1],
				[12, -12, (4/2)-1],[-12, -12, (4/2)-1]]) {
		translate(v = pos) {
			cylinder(h=4, r=3.5, center=true, $fn=60);
		}
	}
}

module p6_holesinabutment()
{
	rotate(a=[90,0,0]) {
		translate(v = [(p6_sizewidth/2)-1-1, 2+1, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
		translate(v = [-(p6_sizewidth/2)+1+1, 2+1, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
	}
}

module p6_sidesupports()
{
	translate(v = [0, 0, ((14+6)/2)-1]) {
		rotate(a=[0, 0, 45]) {
			cube(size = [2, 26.94+0.8, 14+6], center=true);
		}
		rotate(a=[0, 0, -45]) {
			cube(size = [2, 26.94+0.8, 14+6], center=true);
		}
	}
}

module p6_horizontalsupports()
{
	translate(v = [0, 0, (6/2)-1]) {
		cube(size = [31, 2, 6], center=true);
	}
	translate(v = [0, 0, (9/2)-1]) {
		cube(size = [31-8, 2, 9], center=true);
	}
}

module p6_subcomponent()
{
	rotate(a=[90,0,0]) {
		translate(v = [0, (4/2)-1, 0]) {
			cylinder(h=32, r=2, center=true, $fn=60);
		}
	}
	p6_pipesin();
	p6_holesinabutment();
	// holes inside the central cube
	translate(v = [0, 0, (14/2)-1+6]) {
		cube(size = [14-4, 14-4, 14], center=true);
	}
	translate(v = [0, 0, ((14-4.75)/2)-1+6+4.75]) {
		cube(size = [14-4, 14, 14-4.75], center=true);
	}
	// hole to support the arm shaft
	rotate(a=[0,90,0]) {
		translate(v = [-(8/2)-1-4-3, 0, 0]) {
			cylinder(h=16, r=2, center=true, $fn=60);
		}
	}
	// hole in the support for coil spring
	rotate(a=[0,90,0]) {
		translate(v = [-(3/2)-1.5-1-2, 15.5, 0]) {
			cylinder(h=10, r=1, center=true, $fn=60);
		}
	}
	translate(v = [0, 0, -2]) {
		cube(size = [p6_sizewidth+1, p6_sizewidth+1, 2], center=true);
	}
	translate(v = [0, 0, -1]) {
		cube(size = [2, p6_sizewidth+2, 2], center=true);
	}
}

module p6_addcomponent()
{
	cube(size = [p6_sizewidth, p6_sizewidth, 2], center=true);
	rotate(a=[90,0,0]) {
		translate(v = [0, (8/2)-3, 0]) {
			cylinder(h=p6_sizewidth, r=4, center=true, $fn=60);
		}
	}
	p6_pipesout();
	p6_sidesupports();
	// central cube
	translate(v = [0, 0, ((14+6)/2)-1]) {
		cube(size = [14, 14, 14+6], center=true);
	}
	p6_horizontalsupports();
	// support the arm shaft
	rotate(a=[0,90,0]) {
		translate(v = [-(8/2)-1-4-3, 0, 0]) {
			cylinder(h=15, r=4, center=true, $fn=60);
		}
	}
	translate(v = [0, ((15.5-(14/2)+2)/2)+5, 6/2]) {
		cube(size = [8, 15.5-(14/2)+2, 6], center=true);
	}
	// support for coil spring
	rotate(a=[0,90,0]) {
		translate(v = [-(3/2)-1.5-1-2, 15.5, 0]) {
			cylinder(h=9, r=3, center=true, $fn=60);
		}
	}
}

module part06()
{
	difference() {
		union() {
			p6_addcomponent();
		}
		p6_subcomponent();
	}
}

if(frominclude == 0) {
	part06();
}